package com.excesys.exsecs.eco.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.excesys.exsecs.eco.entity.StrategyConst;
import com.excesys.exsecs.eco.entity.StrategyMain;
import com.excesys.exsecs.eco.entity.StrategyVariable;
import com.excesys.exsecs.eco.mapper.StrategyConstMapper;
import com.excesys.exsecs.eco.mapper.StrategyMainMapper;
import com.excesys.exsecs.eco.mapper.StrategyVariableMapper;
import com.excesys.exsecs.eco.service.StrategyMainService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
@RequiredArgsConstructor
public class StrategyMainServiceImpl  extends ServiceImpl<StrategyMainMapper, StrategyMain> implements StrategyMainService {


	private final StrategyMainMapper mainMapper;
	private final StrategyConstMapper constMapper;
	private final StrategyVariableMapper variableMapper;


	@Override
	public List<Map> getStrategy(String ids) {
		String[] split = ids.split(",");
		List<Map> result = new ArrayList<>();
		for (int i = 0; i < split.length; i++) {
			Map strategyMap = new HashMap<>();
			StrategyMain strategyMain = mainMapper.selectById(split[i]);
			List<StrategyConst> constList = constMapper.selectList(Wrappers.<StrategyConst>lambdaQuery()
					.eq(StrategyConst::getParentId, split[i]));
			List<StrategyVariable> variableList = variableMapper.selectList(Wrappers.<StrategyVariable>lambdaQuery()
					.eq(StrategyVariable::getParentId, split[i]));
			strategyMap.put("id",strategyMain.getId());
			strategyMap.put("name",strategyMain.getName());
			strategyMap.put("constData",constList);
			strategyMap.put("varData",variableList);
			result.add(strategyMap);
		}
		return result;
	}
}
